package com.itheima.bos.web.action;

import com.itheima.bos.domain.Decidedzone;
import com.itheima.bos.service.IDecidedzoneService;
import com.itheima.bos.web.action.base.BaseAction;
import com.itheima.crm.service.CustomerService;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * Created by Mr.King on 2017/3/13.
 */
@Component
public class DecidedzoneAction extends BaseAction<Decidedzone> {

    @Autowired
    private IDecidedzoneService decidedzoneService;

    @Autowired
    private CustomerService customerService;

    private String[] subareaid;
    public void setSubareaid(String[] subareaid) {
        this.subareaid = subareaid;
    }

    private Integer[] customerIds;
    public void setCustomerIds(Integer[] customerIds) {
        this.customerIds = customerIds;
    }

    //保存定区
    public String saveOrUpdate(){
        decidedzoneService.save(model,subareaid);
        return "list";
    }

    //分页查询
    public String pageQuery() throws IOException {
        setPage();

        decidedzoneService.pagrQuery(pageBean);

        String[] arr = new String[]{ "detachedCriteria", "pageSize",
                "currentPage", "decidedzone" ,"decidedzones","region"};
        toJSON(pageBean,arr);
        return NONE;
    }

    //未关联查询客户
    public String findCustomerNoAssociation() throws IOException {
        List list = customerService.findnoassociationCustomers();
        String[] excludes = new String[]{"station","telephone","address","decidedzone_id"};
        toJSON(list,excludes);
        return NONE;
    }

    //查询已关联客户
    public String findCustomerAssociation() throws IOException {
        List list = customerService.findhasassociationCustomers(model.getId());
        String[] excludes = new String[]{"station","telephone","address","decidedzone_id"};
        toJSON(list,excludes);
        return NONE;
    }

    //保存关联客户
    public String assigncustomerstodecidedzone(){
        customerService.assignCustomersToDecidedZone(customerIds,model.getId());
        return "list";
    }
}
